package com.clkj.tramcarlibrary.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clkj.tramcarlibrary.R;
import com.clkj.tramcarlibrary.entity.JinzhanDetail;

import java.util.List;

/**
 * Created by Administrator on 2017/2/16.
 */

public class JinzhanAdapter extends BaseAdapter {

    private Context context;
    private List<JinzhanDetail> jinzhanDetailList;

    public JinzhanAdapter(Context context, List<JinzhanDetail> jinzhanDetailList) {
        this.context = context;
        this.jinzhanDetailList = jinzhanDetailList;
    }

    @Override
    public int getCount() {
        return jinzhanDetailList.size();
    }

    @Override
    public Object getItem(int position) {
        return jinzhanDetailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder = null;
        if (convertView == null) {
            myViewHolder = new MyViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_jinzhan_layout, null);

            myViewHolder.tv_station = (TextView) convertView.findViewById(R.id.tv_station);
            myViewHolder.tv_first_time = (TextView) convertView.findViewById(R.id.tv_first_time);
            myViewHolder.tv_first_distance = (TextView) convertView.findViewById(R.id.tv_first_distance);
            myViewHolder.tv_second_time = (TextView) convertView.findViewById(R.id.tv_second_time);
            myViewHolder.tv_second_distance = (TextView) convertView.findViewById(R.id.tv_second_distance);

            convertView.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }

        myViewHolder.tv_station.setText(jinzhanDetailList.get(position).getStationName());
        myViewHolder.tv_first_time.setText(jinzhanDetailList.get(position).getFirstChe());
        myViewHolder.tv_first_distance.setText(jinzhanDetailList.get(position).getFirstDistance());
        myViewHolder.tv_second_time.setText(jinzhanDetailList.get(position).getSecondChe());
        myViewHolder.tv_second_distance.setText(jinzhanDetailList.get(position).getSecondDistance());
        return convertView;
    }

    private class MyViewHolder {
        private TextView tv_station;
        private TextView tv_first_time;
        private TextView tv_first_distance;
        private TextView tv_second_time;
        private TextView tv_second_distance;
    }
}
